Inheriting attributes
#nixlang #AttrSets
https://nixos.org/manual/nix/stable/language/constructs.html#inheriting-attributes
AttrSets を作るのを手助けしてくれる機能。
スコープにある変数をキーに持つAttrSetsを作成できる。例を見たほうがわかりやすい。
code: noinherit.nix
let x = 123; in
{ x = x;
y = 456;
}
上記を以下のように略記できる。
code: inherit.nix
let x = 123; in
{ inherit x;
y = 456;
}
複数の変数をまとめて指定することもできる。
code: multi.nix
{ inherit x y z; }
親がある場合は指定することもできる
code: parents.nix
{ x = p.x;
y = p.y; }
は以下のように書ける
code: parents.nix
{ inherit (p) x y; }
JavaScriptのキー名と値に割り当てる変数名が同じ時に略記できる機能の感覚で使える